package com.fire.social.mapper;

import com.fire.social.entity.node.Content;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public interface ContentMapper extends Neo4jRepository<Content, Long> {

    /**
     * 获取所有动态的ID
     */
    @Query("MATCH (c:Content) RETURN ID(c)")
    List<Long> findAllContentIds();


    /**
     * 获取动态内容
     */
    @Query("match (user:User) where user.account=$account \n" +
            "match ((user)-[:Publish]->(content)) return content")
    List<Content> getContentByAccount(@Param("account") String account);

    /**
     * 获取关注人的动态
     */
    @Query("match (user:User) where user.account=$account\n" +
            "match (user)-[:Follow]->(friends)-[:Publish]->(content) " +
            "return content")
    List<Content> getFriendContents(@Param("account") String account);

    /**
     * 创建动态
     */
    @Query("match (user:User) where user.account=$account\n" +
            "create (c:Content{publish_account:$account,publisher:$publisher,publisher_img:$publisherImg," +
            "title:$title,content:$content,related_hobby:$relatedHobby,hobbyid:$hobbyId,imgurl:$imgUrl,time:$time})\n" +
            "create (user)-[:Publish]->(c) return c")
    Content createContent(@Param("account") String account, @Param("publisher") String publisher, @Param("publisherImg") String publisherImg,
                          @Param("title") String title, @Param("content") String content, @Param("relatedHobby") String relatedHobby,
                          @Param("hobbyId") Long hobbyId, @Param("imgUrl") String imgUrl, @Param("time") String time);


    /**
     * 根据兴趣爱好查动态内容
     */
    @Query("match (user:User) where user.account=$account\n" +
            "match (user)-[:Like]->(hobbies)\n" +
            "match (content:Content) where content.related_hobby in hobbies.hname return content")
    List<Content> findContentByHobby(@Param("account") String account);
}
